﻿<Window
	xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
	xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    xmlns:local="clr-namespace:CloudBackup"    
    xmlns:system="clr-namespace:System;assembly=mscorlib"
    mc:Ignorable="d"    
	x:Class="CloudBackup.MainWindow"
	x:Name="mainWindow"
	Title="Cloud Backup"
    Width="600" Height="300"
	MinWidth="620" MinHeight="450"
    BorderThickness="0,0,0,0">
    
    <!-- Style Resources -->
    <Window.Resources>
        <ResourceDictionary>
            
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="Styles.xaml"/>
            </ResourceDictionary.MergedDictionaries>

            <LinearGradientBrush x:Key="MainWindowContainerBackground" EndPoint="0.5,1" StartPoint="0.5,0">
                <GradientStop Color="#FFF1F3F4" Offset="0"/>
                <GradientStop Color="#FF8C8D8D" Offset="1"/>
            </LinearGradientBrush>

            <LinearGradientBrush x:Key="GrayGradientColor" EndPoint="0.5,1" StartPoint="0.5,0">
                <GradientStop Color="#FF9B9B9B" Offset="0"/>
                <GradientStop Color="#00FFFFFF" Offset="1"/>
            </LinearGradientBrush>
            
            <LinearGradientBrush x:Key="ButtonBackgroundNormal" MappingMode="Absolute" StartPoint="33.334,49.667" EndPoint="33.334,69.667">
                <LinearGradientBrush.Transform>
                    <MatrixTransform Matrix="1.000,0.000,-0.000,-1.000,-10.333,70.167" />
                </LinearGradientBrush.Transform>
                <GradientStop Offset="0.00" Color="#ff323232"/>
                <GradientStop Offset="1.00" Color="#ff5d5d5d"/>
            </LinearGradientBrush>

            <LinearGradientBrush x:Key="ButtonBackgroundOver" EndPoint="33.334,69.667" StartPoint="33.334,49.667" MappingMode="Absolute">
                <LinearGradientBrush.Transform>
                    <MatrixTransform Matrix="1,0,0,-1,-10.333,70.167"/>
                </LinearGradientBrush.Transform>
                <GradientStop Color="#FF000000" Offset="0"/>
                <GradientStop Color="#FF5D5D5D" Offset="1"/>
            </LinearGradientBrush>

            <!-- BackupButton Style -->
            <Style x:Key="BackupButton" TargetType="{x:Type Button}">
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type Button}">
                            <Grid>
                                <Viewbox d:LayoutOverrides="Height">
                                    <Canvas Width="46.000" Height="21.000">
                                        <Path StrokeThickness="1.0" Stroke="{DynamicResource ButtonBackgroundBorder}" StrokeMiterLimit="1.0" Data="F1 M 45.500,15.955 C 45.500,18.465 43.210,20.500 40.387,20.500 L 5.613,20.500 C 2.789,20.500 0.500,18.465 0.500,15.955 L 0.500,5.045 C 0.500,2.535 2.789,0.500 5.613,0.500 L 40.387,0.500 C 43.210,0.500 45.500,2.535 45.500,5.045 L 45.500,15.955 Z" Fill="{DynamicResource ButtonBackgroundNormal}" x:Name="path"/>
                                        <Path StrokeThickness="0.3" Stroke="#ffffffff" StrokeLineJoin="Round" Fill="#fff1f1f1" Data="F1 M 26.848,13.729 L 23.481,13.776 L 26.710,10.545 L 23.571,7.271 L 26.757,7.224 L 30.078,10.545 L 26.848,13.729 Z"/>
                                        <Path StrokeThickness="0.3" Stroke="#ffffffff" StrokeLineJoin="Round" Fill="#fff1f1f1" Data="F1 M 20.290,13.729 L 16.922,13.776 L 20.152,10.545 L 17.013,7.271 L 20.198,7.224 L 23.519,10.545 L 20.290,13.729 Z"/>
                                    </Canvas>
                                </Viewbox>
                            </Grid>
                            <ControlTemplate.Triggers>
                                <Trigger Property="IsMouseOver" Value="True">
                                    <Setter Property="Fill" TargetName="path" Value="{DynamicResource ButtonBackgroundOver}"/>
                                </Trigger>
                            </ControlTemplate.Triggers>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>

            <!-- RestoreButton Style-->
            <Style x:Key="RestoreButton" TargetType="{x:Type Button}">
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type Button}">
                            <Grid>
                                <Viewbox>
                                    <Canvas Width="46.000" Height="21.000">
                                        <Path StrokeThickness="1.0" Stroke="{DynamicResource ButtonBackgroundBorder}" StrokeMiterLimit="1.0" Data="F1 M 45.500,15.955 C 45.500,18.465 43.210,20.500 40.387,20.500 L 5.613,20.500 C 2.789,20.500 0.500,18.465 0.500,15.955 L 0.500,5.045 C 0.500,2.535 2.789,0.500 5.613,0.500 L 40.387,0.500 C 43.210,0.500 45.500,2.535 45.500,5.045 L 45.500,15.955 Z" Fill="{DynamicResource ButtonBackgroundNormal}" x:Name="path"/>
                                        <Path StrokeThickness="0.3" Stroke="#ffffffff" StrokeLineJoin="Round" Fill="#fff1f1f1" Data="F1 M 20.152,7.271 L 23.519,7.224 L 20.290,10.455 L 23.429,13.729 L 20.243,13.776 L 16.922,10.455 L 20.152,7.271 Z"/>
                                        <Path StrokeThickness="0.3" Stroke="#ffffffff" StrokeLineJoin="Round" Fill="#fff1f1f1" Data="F1 M 26.710,7.271 L 30.078,7.224 L 26.848,10.455 L 29.987,13.729 L 26.802,13.776 L 23.481,10.455 L 26.710,7.271 Z"/>
                                    </Canvas>
                                </Viewbox>
                            </Grid>
                            <ControlTemplate.Triggers>
                                <Trigger Property="IsMouseOver" Value="True">
                                    <Setter Property="Fill" TargetName="path" Value="{DynamicResource ButtonBackgroundOver}"/>
                                </Trigger>
                            </ControlTemplate.Triggers>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>

            <!-- CancelButton style -->
            <Style x:Key="CancelButton" TargetType="{x:Type Button}">
                <Setter Property="FocusVisualStyle" Value="{DynamicResource SimpleButtonFocusVisual}"/>
                <Setter Property="Background" Value="{DynamicResource NormalBrush}"/>
                <Setter Property="BorderBrush" Value="{DynamicResource NormalBorderBrush}"/>
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type Button}">
                            <Grid x:Name="Grid">
                                <Rectangle Margin="0,0,0,0" Fill="{DynamicResource ButtonBackgroundNormal}" Stroke="{DynamicResource LightBorderBrush}" RadiusX="3" RadiusY="3" StrokeThickness="0.5" x:Name="rectangle"/>
                                <!-- Content Presenter is where the text content etc is placed by the control -->
                                <ContentPresenter HorizontalAlignment="Stretch" Margin="8,4,8,4" RecognizesAccessKey="True"/>
                            </Grid>
                            <!--Each state sets a brush on the Border in the template -->
                            <ControlTemplate.Triggers>
                                <Trigger Property="IsMouseOver" Value="true">
                                    <Setter Property="Fill" TargetName="rectangle" Value="{DynamicResource ButtonBackgroundOver}"/>
                                </Trigger>
                                <Trigger Property="IsEnabled" Value="false">
                                    <Setter Property="Foreground" Value="{DynamicResource DisabledForegroundBrush}"/>
                                </Trigger>
                            </ControlTemplate.Triggers>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>

            <!-- ProgressBarStyle -->
            <Style x:Key="ProgressBarStyle" TargetType="{x:Type ProgressBar}">
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type ProgressBar}">
                            <Grid>
                                <!-- This Border is the track. It must be named PART_Track -->
                                <Border x:Name="PART_Track" Background="{DynamicResource PressedBrush}" BorderBrush="{DynamicResource SolidBorderBrush}" BorderThickness="1" CornerRadius="2"/>
                                <!-- This Border shows progress. It must be named PART_Indicator for the control to function -->
                                <Border HorizontalAlignment="Left" x:Name="PART_Indicator" Background="{DynamicResource ButtonBackgroundNormal}" BorderBrush="{x:Null}" BorderThickness="1" CornerRadius="2"/>
                            </Grid>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
            
            <local:VirtualMachineImageConverter x:Key="VirtualMachineImageConverter"/>
            
            <!-- Local VM Data source and template -->
            <ObjectDataProvider x:Key="LocalVirtualMachineProvider" d:IsDataSource="True" ObjectType="{x:Type local:VirtualMachineProvider}" MethodName="GetLocalVirtualMachines" IsAsynchronous="True">
                <ObjectDataProvider.MethodParameters>
                    <system:Boolean>false</system:Boolean>
                </ObjectDataProvider.MethodParameters>
            </ObjectDataProvider>
            <DataTemplate x:Key="LocalVirtualMachineDataTemplate">
                <Border BorderBrush="#FFe1e1e1" BorderThickness="0,0,0,0.5">
                    <StackPanel Orientation="Horizontal" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Width="Auto" Height="Auto" Margin="5">
                        <Image Source="{Binding Converter={StaticResource VirtualMachineImageConverter}, IsAsync=True}" Width="70" Height="75" />
                        <StackPanel VerticalAlignment="Center">                            
                            <TextBlock Text="{Binding Path=Name}" FontSize="11"/>
                        </StackPanel>
                    </StackPanel>
                </Border>
            </DataTemplate>
            
            <!-- Remote VM Data source and template -->
            <ObjectDataProvider x:Key="RemoteVirtualMachineProvider" d:IsDataSource="True" ObjectType="{x:Type local:VirtualMachineProvider}" MethodName="GetRemoteVirtualMachines" IsAsynchronous="True">
                <ObjectDataProvider.MethodParameters>
                    <system:Boolean>false</system:Boolean>
                </ObjectDataProvider.MethodParameters>
            </ObjectDataProvider>
            <DataTemplate x:Key="RemoteVirtualMachineDataTemplate">
                <Border BorderBrush="#FFe1e1e1" BorderThickness="0,0,0,0.5">
                    <StackPanel Orientation="Horizontal" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Width="Auto" Height="Auto" Margin="5">
                        <Image Source="images/server1.png" Width="70" Height="75" />
                        <StackPanel VerticalAlignment="Center">
                            <TextBlock Text="{Binding Path=Name}" FontSize="11"/>
                            <TextBlock Text="{Binding Path=LastModified}" FontSize="11"/>
                        </StackPanel>
                    </StackPanel>
                </Border>
            </DataTemplate>


        </ResourceDictionary>
    </Window.Resources>
    
    <Grid x:Name="LayoutRoot" Margin="0">
        <Grid.Background>
            <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                <GradientStop Color="#FF0F0F0F" Offset="0"/>
                <GradientStop Color="#FF00090F" Offset="1"/>
            </LinearGradientBrush>
        </Grid.Background>

        <Canvas HorizontalAlignment="Left" VerticalAlignment="Top" Width="704" Height="524" d:IsLocked="True">
            <Image HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Width="Auto" Height="Auto" Source="images\backgroundLighting.png"/>
        </Canvas>

        <Rectangle HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Width="Auto" Height="Auto" Stroke="{x:Null}" RadiusX="5" RadiusY="5" Margin="20,60,20,20" Fill="{DynamicResource MainWindowContainerBackground}"/>

        <Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Width="Auto" Height="Auto" Margin="40,60,40,30" Grid.ColumnSpan="3">
            <Grid.RowDefinitions>
                <RowDefinition Height="30"/>
                <RowDefinition Height="0.915*"/>
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="0.45*"/>
                <ColumnDefinition Width="70"/>
                <ColumnDefinition Width="0.45*"/>
            </Grid.ColumnDefinitions>
            <Grid Grid.Row="0" Grid.Column="0">
                <TextBlock Text="Local Virtual Machines" TextWrapping="NoWrap" HorizontalAlignment="Left" Margin="0" VerticalAlignment="Center" FontSize="11"/>
            </Grid>
            <Grid Grid.Row="0" Grid.Column="2">
                <TextBlock Text="Remote Backups" TextWrapping="NoWrap" HorizontalAlignment="Left" Margin="0" VerticalAlignment="Center" FontSize="11"/>
            </Grid>

            <!-- Local VM ListBox -->
            <Grid Grid.Row="1" Grid.Column="0">
                <Rectangle HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Width="Auto" Height="Auto" Fill="#FFFFFFFF" RadiusX="5" RadiusY="5" Stroke="#FF9B9B9B" OpacityMask="{x:Null}"/>
                <ListBox Name="localVirtualMachineListBox" HorizontalAlignment="Stretch" Style="{DynamicResource SimpleListBox}" VerticalAlignment="Stretch" Width="Auto" Height="Auto" Margin="5,10,5,10" ItemsSource="{Binding Mode=OneWay, Source={StaticResource LocalVirtualMachineProvider}}" ItemTemplate="{DynamicResource LocalVirtualMachineDataTemplate}" SelectionChanged="OnListBoxSelectionChanged">
                    <ListBox.Resources>
                        <SolidColorBrush x:Key="{x:Static SystemColors.ControlTextBrushKey}" Color="#FF3d3d3d" />
                        <SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="#FFcde1ef" />
                        <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="#FFcde1ef" />
                        <SolidColorBrush x:Key="{x:Static SystemColors.HighlightTextBrushKey}" Color="#FF3d3d3d" />
                        <SolidColorBrush x:Key="{x:Static SystemColors.ScrollBarBrush}" Color="Black" />
                    </ListBox.Resources>
                </ListBox>
                <Path Fill="{DynamicResource GrayGradientColor}" HorizontalAlignment="Stretch" Margin="0,0.944,0,0" x:Name="Shadow" VerticalAlignment="Top" Width="Auto" Height="9.206" Stretch="Fill" Stroke="{x:Null}">
                    <Path.Data>
                        <PathGeometry>
                            <PathFigure IsClosed="True" StartPoint="0,3">
                                <BezierSegment Point1="0,1.34314575050762" Point2="1.34314575050762,0" Point3="3,0" IsSmoothJoin="True"/>
                                <LineSegment Point="274,0" IsSmoothJoin="True"/>
                                <BezierSegment Point1="275.656854249492,0" Point2="277,1.34314575050762" Point3="277,3" IsSmoothJoin="True"/>
                                <PolyBezierSegment Points="277,7.6666667 277,9.2074757 277,9.2074757 277,9.2074757 0,9.2074757 0,9.2074757 0,9.2074757 0,7.6666667 0,3"/>
                            </PathFigure>
                        </PathGeometry>
                    </Path.Data>
                </Path>
            </Grid>

            <!-- Backup/Restore Button -->
            <Grid Grid.Row="1" Grid.Column="1" HorizontalAlignment="Center" VerticalAlignment="Center">
                <Button Margin="0,0,0,0" Style="{DynamicResource BackupButton}" Content="Button" Name="btnBackup" Click="OnBackupClick" Cursor="Hand" Width="46" Height="21" Focusable="False" IsEnabled="{Binding ElementName=localVirtualMachineListBox, Path=SelectedItems.Count}"/>
                <Button Margin="0,60,0,0" Style="{DynamicResource RestoreButton}" Content="Button" Height="21" VerticalAlignment="Center" Click="OnRestoreClick" Name="btnRestore" Cursor="Hand" Width="46" Focusable="False" IsEnabled="{Binding ElementName=remoteVirtualMachineListBox, Path=SelectedItems.Count}"/>
            </Grid>

            <!-- Remote VM ListBox -->
            <Grid Grid.Row="1" Grid.Column="2">
                <Rectangle HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Width="Auto" Height="Auto" RadiusX="5" RadiusY="5" Fill="#FFFFFFFF" Stroke="#FF9B9B9B"/>
                <ListBox Name="remoteVirtualMachineListBox" HorizontalAlignment="Stretch" Style="{DynamicResource SimpleListBox}" VerticalAlignment="Stretch" Width="Auto" Height="Auto" Margin="5,10,5,10" ItemsSource="{Binding Mode=OneWay, Source={StaticResource RemoteVirtualMachineProvider}}" ItemTemplate="{DynamicResource RemoteVirtualMachineDataTemplate}" SelectionChanged="OnListBoxSelectionChanged">
                    <ListBox.Resources>
                        <SolidColorBrush x:Key="{x:Static SystemColors.ControlTextBrushKey}" Color="#FF3d3d3d" />
                        <SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="#FFcde1ef" />
                        <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="#FFcde1ef" />
                        <SolidColorBrush x:Key="{x:Static SystemColors.HighlightTextBrushKey}" Color="#FF3d3d3d" />
                        <SolidColorBrush x:Key="{x:Static SystemColors.ScrollBarBrush}" Color="Black" />
                        <SolidColorBrush x:Key="{x:Static SystemColors.ActiveBorderBrushKey}" Color="Red" />
                    </ListBox.Resources>
                </ListBox>
                <Path Fill="{DynamicResource GrayGradientColor}" HorizontalAlignment="Stretch" Margin="0,0.944,0,0" x:Name="Shadow_Copy" VerticalAlignment="Top" Width="Auto" Height="9.206" Stretch="Fill" Stroke="{x:Null}">
                    <Path.Data>
                        <PathGeometry>
                            <PathFigure IsClosed="True" StartPoint="0,3">
                                <BezierSegment Point1="0,1.34314575050762" Point2="1.34314575050762,0" Point3="3,0" IsSmoothJoin="True"/>
                                <LineSegment Point="274,0" IsSmoothJoin="True"/>
                                <BezierSegment Point1="275.656854249492,0" Point2="277,1.34314575050762" Point3="277,3" IsSmoothJoin="True"/>
                                <PolyBezierSegment Points="277,7.6666667 277,9.2074757 277,9.2074757 277,9.2074757 0,9.2074757 0,9.2074757 0,9.2074757 0,7.6666667 0,3"/>
                            </PathFigure>
                        </PathGeometry>
                    </Path.Data>
                </Path>
            </Grid>

        </Grid>
        
        <!-- Progress Window -->
        <Grid Background="#F2031C2F" Visibility="Hidden" Name="ProgressPanel" VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
            <StackPanel VerticalAlignment="Center" HorizontalAlignment="Center">
                <ProgressBar Name="progressBar" Style="{DynamicResource ProgressBarStyle}" Height="20" Value="55" Width="340" Maximum="100" Minimum="0"/>
                <Label FontSize="20" Foreground="#FFFFFFFF" Name="progressPercentLabel" Content="55%..." Height="40" HorizontalAlignment="Center" VerticalContentAlignment="Center"/>
                <Label Name="progressDescription" Content="Backingup Web Server 4" Height="30" Foreground="#FFFFFFFF" HorizontalAlignment="Center" VerticalContentAlignment="Center"/>
                <Button Style="{DynamicResource CancelButton}" Content="Cancel" Foreground="#FFFFFFFF" FontSize="11" Height="25" Width="Auto" Click="OnCancelClick" HorizontalAlignment="Center" Margin="5"/>
            </StackPanel>
            <TextBlock Name="progressTitle" HorizontalAlignment="Left" VerticalAlignment="Top" Text="CloudBackup" TextWrapping="NoWrap" Margin="20,20,0,0" Foreground="#FFFFFFFF" FontSize="14"/>            
        </Grid>
        
    </Grid>
</Window>